#include <boost/asio/ip/tcp.hpp>
#include <cstdint>
#include <functional>
#include <iostream>
#include <memory>
#include <thread>
#include <unistd.h>
#include "MessageBuffer.hpp"
#include "NetworkThread.hpp"
#include "Socket.hpp"
#include "Server.hpp"
#include "World.hpp"
#include "WorldSession.hpp"
#include "WorldSocket.hpp"
#include "WorldMaster.hpp"
class WorldNetworkThread : public NetworkThread<WorldSocket>
{
public:
  void AddSocketed(std::shared_ptr<WorldSocket> new_sc) override
  {
    std::cout << "add socket, ip:" << new_sc->GetRemoteAddress() << std::endl;
    sWorld->AddSession(std::move(std::make_shared<WorldSession>(std::move(new_sc))));
  }

  void RemoveSocketed(std::shared_ptr<WorldSocket> rm_sc) override
  {
    std::cout << "remove socket, ip:" << rm_sc->GetRemoteAddress() << std::endl;
  }
};

int main(int argc, char* argv[]) 
{
  Server<WorldNetworkThread> svr(7001, 1);

  svr.SetPrepareStopCallback(std::bind(&WorldMaster::Stop, sWorldMaster));

  svr.Start();

  return 0;
}